package com.fau.hm.util;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @desc 发送Http请求工具类
 * @author liy
 * @datetime 2014年10月24日,下午10:46:33
 */
@Component
public class HttpRequestUtil {
	
	private static final Logger log = Logger.getLogger(HttpRequestUtil.class);
	
	@Value("${server.local.name}")
	private String urlPath;
	
	@Autowired
	HttpSession session;
	
	/**
	 * @desc 刷新话务系统角色
	 * @author kangyj
	 * @datetime 2015年3月24日,下午3:05:59
	 */
	@Async
	public void refreshCmRole() {
		StringBuilder get_url = new StringBuilder(urlPath);
		get_url.append("/cm/refresh-role");
		
		try {
			URL getUrl= new URL(get_url.toString());
			
			HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
			connection.setConnectTimeout(5000);  
			connection.setReadTimeout(5000);
			connection.connect();
			connection.getInputStream();
			connection.disconnect();
		} catch (IOException e) {
			log.error(e.getMessage());
		}
	}
	
	/**
	 * @desc 刷新订单系统角色
	 * @author kangyj
	 * @datetime 2015年3月24日,下午3:05:59
	 */
	@Async
	public void refreshOmRole() {
		StringBuilder get_url = new StringBuilder(urlPath);
		get_url.append("/om/refresh-role");
		
		try {
			URL getUrl= new URL(get_url.toString());
			
			HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
			connection.setConnectTimeout(5000);  
			connection.setReadTimeout(5000);
			connection.connect();
			connection.getInputStream();
			connection.disconnect();
		} catch (IOException e) {
			log.error(e.getMessage());
		}
	}
	
	/**
	 * @desc 刷新仓储系统角色
	 * @author kangyj
	 * @datetime 2015年3月24日,下午3:05:59
	 */
	@Async
	public void refreshWmRole() {
		StringBuilder get_url = new StringBuilder(urlPath);
		get_url.append("/wm/refresh-role");
		
		try {
			URL getUrl= new URL(get_url.toString());
			
			HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
			connection.setConnectTimeout(5000);  
			connection.setReadTimeout(5000);
			connection.connect();
			connection.getInputStream();
			connection.disconnect();
		} catch (IOException e) {
			log.error(e.getMessage());
		}
	}
	
	/**
	 * @desc 刷新媒体系统角色
	 * @author kangyj
	 * @datetime 2015年3月24日,下午3:05:59
	 */
	@Async
	public void refreshMmRole() {
		StringBuilder get_url = new StringBuilder(urlPath);
		get_url.append("/mm/refresh-role");
		
		try {
			URL getUrl= new URL(get_url.toString());
			
			HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
			connection.setConnectTimeout(5000);  
			connection.setReadTimeout(5000);
			connection.connect();
			connection.getInputStream();
			connection.disconnect();
		} catch (IOException e) {
			log.error(e.getMessage());
		}
	}
	
	/**
	 * @desc 刷新统计系统角色
	 * @author kangyj
	 * @datetime 2015年3月24日,下午3:05:59
	 */
	@Async
	public void refreshSsRole() {
		StringBuilder get_url = new StringBuilder(urlPath);
		get_url.append("/ss/refresh-role");
		
		try {
			URL getUrl= new URL(get_url.toString());
			
			HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
			connection.setConnectTimeout(5000);  
			connection.setReadTimeout(5000);
			connection.connect();
			connection.getInputStream();
			connection.disconnect();
		} catch (IOException e) {
			log.error(e.getMessage());
		}
	}
	
	/**
	 * @desc 刷新财务系统角色
	 * @author kangyj
	 * @datetime 2015年3月24日,下午3:05:59
	 */
	@Async
	public void refreshFmRole() {
		StringBuilder get_url = new StringBuilder(urlPath);
		get_url.append("/fm/refresh-role");
		
		try {
			URL getUrl= new URL(get_url.toString());
			
			HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
			connection.setConnectTimeout(5000);  
			connection.setReadTimeout(5000);
			connection.connect();
			connection.getInputStream();
			connection.disconnect();
		} catch (IOException e) {
			log.error(e.getMessage());
		}
	}
	
	public String getUrlPath() {
		return urlPath;
	}

	public void setUrlPath(String urlPath) {
		this.urlPath = urlPath;
	}
	
}